package com.cjh.consumer;

import org.springframework.amqp.core.ExchangeTypes;
import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

@Component
public class RoutingTopicConsumer {

    @RabbitListener(bindings = {
        @QueueBinding(
                value = @Queue("topicQueue1"),
                key = {"user.*"},
                exchange = @Exchange(name = "topics", type = ExchangeTypes.TOPIC)
        )})
    public void receive1(String message) {
        System.out.println("消费者 user.*【1】接收到消息：" + message);
    }

    @RabbitListener(bindings = {
        @QueueBinding(
                value = @Queue("topicQueue2"),
                key = {"user.#"},
                exchange = @Exchange(name = "topics", type = ExchangeTypes.TOPIC)
        )})
    public void receive2(String message) {
        System.err.println("消费者 user.#【2】接收到消息：" + message);
    }
}